The ABORT IF conditions are used when you want to make sure that a certain item in the MPL model is defined correctly. They can be a very important tool to validate your model especially when importing indexes and data from external sources.
In the example below, MPL will stop and display an error message because the index Top3Plants does not contain 3 elements.
INDEX plants := (Atlanta, Chicago, Dallas, NewYork, SanDiego); Top3Plants[plants] := (Atlanta, Chicago, Dallas, SanDiego); ABORT IF NOT (count(Top3Plants) = 3) MESSAGE "The number of plants in Top3Plants must be 3";
In the example below, we are checking if two subset indexes, which should be mutually exclusive, have any common elements. As both indexes contain the city Dallas MPL will stop and issue the error message.
INDEX EastCoast[plants] := (Atlanta, Chicago, Dallas, NewYork); WestCoast[plants] := (Dallas, SanDiego); ABORT IF FORSOME(plants IN EastCoast: plants IN WestCoast) MESSAGE "One of the EastCoast plants is also in WestCoast";
You can also use the ABORT IF condition to check if the values of the datavectors are within the allowed range. For example, in the example below, the capacity for each plant must be at least 200.
DATA Capacity[plants] := (120, 300, 250, 400, 500); ABORT IF FORSOME(plants: Capacity[plants] < 200) MESSAGE Capacity for each plant must be at least 200;